<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Transfer;
use App\Admin\Actions\TransferLead;
use App\Admin\Grid\Filter\TimestampBetween;
use App\AdminRecord;
use App\Lead;
use App\Project;
use App\User;
use Carbon\Carbon;
use Doctrine\DBAL\Schema\Table;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class LeadController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '线索管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Lead());

        $grid->column('leads_id', __('id'));

        $grid->column('name', __('线索名称'));
        $grid->column('source', __('线索来源'));
        $grid->column('mobile', __('手机号'));
        $grid->column('industry', __('行业'));
        $grid->column('level', __('等级'));

        $grid->column('remark', __('Remark'));
        $grid->column('creater.realname', __('创建人'));
        $grid->column('owner.realname', __('负责人'));






        $grid->disableBatchActions();
        $grid->column('project.name', __('项目'));
        $grid->filter(function (Grid\Filter $filter){
            $filter->in('project_id', '项目')->multipleSelect(Project::getSelectOptions());
            $filter->in('create_user_id', '创建者')->multipleSelect(User::getSelectOptions());
            $filter->in('owner_user_id', '负责人')->multipleSelect(User::getSelectOptions());
            $filter->use(new TimestampBetween('create_time','创建时间'))->datetime();;
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Lead::findOrFail($id));

        $show->field('leads_id', __('Leads id'));
        $show->field('customer_id', __('Customer id'));
        $show->field('is_transform', __('Is transform'));
        $show->field('name', __('Name'));
        $show->field('source', __('Source'));
        $show->field('mobile', __('Mobile'));
        $show->field('industry', __('Industry'));
        $show->field('level', __('Level'));
        $show->field('detail_address', __('Detail address'));
        $show->field('remark', __('Remark'));
        $show->field('create_user_id', __('Create user id'));
        $show->field('owner_user_id', __('Owner user id'));
        $show->field('next_time', __('Next time'));
        $show->field('follow', __('Follow'));
        $show->field('create_time', __('Create time'));
        $show->field('update_time', __('Update time'));
        $show->field('crm_vfnlcv', __('Crm vfnlcv'));
        $show->field('project_id', __('Project id'));
        $show->field('crm_zcwekw', __('Crm zcwekw'));
        $show->field('telephone', __('Telephone'));
        $show->field('status', __('Status'));
        $show->field('clue_id', __('Clue id'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Lead());

        $form->number('customer_id', __('Customer id'));
        $form->switch('is_transform', __('Is transform'));
        $form->text('name', __('Name'));
        $form->text('source', __('Source'));
        $form->mobile('mobile', __('Mobile'));
        $form->text('industry', __('Industry'));
        $form->text('level', __('Level'));
        $form->text('detail_address', __('Detail address'));
        $form->textarea('remark', __('Remark'));
        $form->number('create_user_id', __('Create user id'));
        $form->number('owner_user_id', __('Owner user id'));
        $form->number('next_time', __('Next time'));
        $form->text('follow', __('Follow'));
        $form->number('create_time', __('Create time'));
        $form->number('update_time', __('Update time'));
        $form->text('crm_vfnlcv', __('Crm vfnlcv'));
        $form->number('project_id', __('Project id'));
        $form->text('crm_zcwekw', __('Crm zcwekw'));
        $form->text('telephone', __('Telephone'));
        $form->text('status', __('Status'))->default('潜在客户');
        $form->text('clue_id', __('Clue id'));

        return $form;
    }
}
